﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppWPF.Models
{
    class CustomValidationRut : ValidationAttribute
    {
        HospitalEntities contexto = new HospitalEntities();
        Paciente pacin = new Paciente();

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            int valor = (int)value;
            pacin = contexto.Paciente.SingleOrDefault(p => p.Rut == valor);
            if (pacin != null)
            {
                return new ValidationResult("Este Paciente Ya Existe");
            }
            else
            {
                return ValidationResult.Success;
            }
        }
    }
}
